import { defineConfig } from 'vite'
import vue from '@vitejs/plugin-vue'
import vueJsx from "@vitejs/plugin-vue-jsx";
import styleImport from 'vite-plugin-style-import';
import { viteMockServe } from 'vite-plugin-mock'
import path from 'path'
export default defineConfig({
  build:{
    //构建后是否生成 source map 文件。
    sourcemap:true
  },
  base: './',
  plugins: [vue(), vueJsx(), viteMockServe({ supportTs: false }),styleImport({
    libs: [
      {
        libraryName: 'vant',
        esModule: true,
        resolveStyle: (name) => `vant/es/${name}/style`,
      },
    ],
  }),
  ],
  resolve: {
    alias: {
      '@': path.resolve(__dirname, 'src'),
      'comps': path.resolve(__dirname, 'src/components'),
      'pages': path.resolve(__dirname, 'src/pages'),
      'styles': path.resolve(__dirname, 'src/styles'),
      'routes': path.resolve(__dirname, 'src/routes'),
      'store': path.resolve(__dirname, 'src/store'),
      'api': path.resolve(__dirname, 'src/api'),
      'assets': path.resolve(__dirname, 'src/assets'),
      "views":path.resolve(__dirname,'src/views'),
      'utils': path.resolve(__dirname, 'src/utils'),
      'hooks':path.resolve(__dirname,'src/hooks')
    }
  },
  //默认情况下，不在 node_modules 中的 链接的包不会被预构建。使用此选项可强制预构建链接的包。(可选配置)
  optimizeDeps:{
    include:['lib-flexible','axios']
  },
  server: {
    port:3000,
    host:'0.0.0.0',
    open: false,
    proxy: {
      '/auth': {
        target: 'https://qingyanjingzhun.com',
        // target: 'http://8.133.190.31:8080',
        // target : 'http://192.168.1.4:8080',
        changeOrigin: true,
        rewrite: path => path.replace(/^\/auth/, '/auth')
      },
      '/api': {
        target: 'https://qingyanjingzhun.com',
        // target: 'http://8.133.190.31:8080',
        // target : 'http://192.168.1.4:8080',
        changeOrigin: true,
        rewrite: path => path.replace(/^\/api/, '')
      }
    },
    cors:true
  }
})